<?php

//1.得到当前登陆者信息
//sesion用于动态页面之间的传值
session_start();

if (!isset($_SESSION["userinfo"])) {
    $result = array("msg" => "请先登录", "status" => 2);
    print_r(json_encode($result));
    return;
}

$userId = json_decode(json_encode($_SESSION["userinfo"]))->u_id;
include "./DBheuper.php";

//准备sql语句

$querySQL = "SELECT *FROM `cartslist` WHERE uid='".$userId."'";

$resultData = sqlQuery($querySQL);

$resultJSON = array("msg" => "查询失败", "status" => 3);


if ($resultData->num_rows >= 1) {
    $resultJSON["msg"] = "查询完成";
    $resultJSON["status"] = 1;


    $data = array();
    // fetch_assoc()每一次只能读取1条
    while ($row = $resultData->fetch_assoc()) {
        array_push($data, $row);
    }

    $resultJSON["data"] = $data;
}

print_r(json_encode($resultJSON));
